<template>
	<view class="page">
		<!-- <view class=" padding box">
			<view class="card">
				<view class=" border-bottom padding-bottom-sm margin-bottom-sm">
					<span>用户编号:</span>{{info.user_no}}
				</view>
				<view class="border-bottom padding-bottom-sm margin-bottom-sm">
					<span>用户手机号:</span>{{info.mobile}}
				</view>
				<view class="border-bottom padding-bottom-sm margin-bottom-sm">
					<span>微信open_id:</span>{{info.open_id}}
				</view>
				<view class="border-bottom padding-bottom-sm margin-bottom-sm">
					<span>来源渠道:</span>{{info.source}}
				</view>
				<view class="border-bottom padding-bottom-sm margin-bottom-sm">
					<span>所属商铺:</span>{{info.store_id_dictText}}
				</view>
				<view class="margin-bottom-sm ">
					<span>备注信息:</span>{{info.description}}
				</view>
			</view>
		</view> -->
		<view class="nlist">
			<view class="nitem">
				<view class="oneitem">
					<image class="tous" src="/static/icon/icon_hy_yh.png" mode=""/>
					<text class="onename">{{info.user_no}}</text>
					<view class="zixing">自行注册账号</view>
				</view>
				<view class="twoitem">
					<view class="hengone heng">
						<view class="hitem">
							<text class="hleft">手机号：</text>
							<text class="hright txt">{{info.mobile||'暂无'}}</text>
						</view>
						<!-- <view class="hitem ban">
							<text class="hleft">来源：</text>
							<text class="hright txt">{{info.source}}</text>
						</view> -->
					</view>
					<view class="hengone heng" v-if="info.source">
						<view class="hitem">
							<text class="hleft">来源渠道:</text>
							<text class="hright txt">{{info.source||'暂无'}}</text>
						</view>
					</view>
					<view class="hengone heng" v-if="info.store_id_dictText">
						<view class="hitem">
							<text class="hleft">所属商铺:</text>
							<text class="hright txt">{{info.store_id_dictText||'暂无'}}</text>
						</view>
					</view>
					<view class="hengone heng" v-if="info.open_id">
						<view class="hitem">
							<text class="hleft">微信openid:</text>
							<text class="hright txt">{{info.open_id||'暂无'}}</text>
						</view>
					</view>
					
					<view class="hengone heng" v-if="info.description">
						<view class="hitem">
							<text class="hleft">备注信息:</text>
							<text class="hright txt">{{info.description}}</text>
						</view>
					</view>

				</view>
			</view>
		</view>
		<view class="footer">
			<!-- <wd-button @click="toggleChangeUserPhone">修改用户手机号</wd-button>
			<wd-button @click="toggleVoucherLssuance">分发优惠券</wd-button>
			<wd-button @click="toggleConsu">查看消费记录</wd-button> -->
			<view class="fbtn" @click="toggleChangeUserPhone">修改手机号</view>
			<view class="fbtn" @click="toggleVoucherLssuance">分发优惠券</view>
			<view class="fbtn cha" @click="toggleConsu">查看消费记录</view>
		</view>
		<wd-message-box />
		<wd-notify />
	</view>
</template>

<script setup>
	import {
		onLoad,
		onShow
	} from '@dcloudio/uni-app'
	import userApiService from "@/api/user.js"
	import {
		useMessage,
		useNotify
	} from '@/uni_modules/wot-design-uni'
	import {
		ref
	} from "vue"
	const {
		showNotify,
		closeNotify
	} = useNotify()

	const message = useMessage()

	let id = 9
	const newPhone = ref()
	const info = ref({
		address: "",
		avatar: "",
		birthday: "",
		description: "",
		mobile: "",
		open_id: "",
		operator: "",
		sex: null,
		source: "",
		store_id: 9,
		store_id_dictText: "",
		user_no: "",
	})

	onLoad((e) => {
		id = e.id
		init()
	})

	const init = () => {
		userApiService.detail({
			id: id
		}).then(res => {
			info.value = res
		})
	}

	const isPhone = (phone) => {
		const myreg = /^1[3-9]\d{9}$/;
		return myreg.test(phone)
	}

	const toggleChangeUserPhone = () => {
		newPhone.value = info.value.mobile
		message
			.prompt({
				title: '请输入用户新手机号',
				inputValue: newPhone.value,
				inputType: "number",
				inputPlaceholder: "请输入手机号"
			})
			.then((resp) => {
				if (resp.action === "confirm") {
					if (isPhone(resp.value)) {
						userApiService.update({
							...info.value,
							mobile: resp.value
						}).then(res => {
							showNotify({
								type: 'success',
								message: '修改手机号成功'
							})
							init()
						})

					} else {
						uni.showToast({
							title: "请输入正确的手机号",
							icon: "none"
						})
					}
				}
			})
			.catch((error) => {
				console.log(error)
			})
	}

	const toggleVoucherLssuance = () => {
		uni.navigateTo({
			url: `/pages/user/voucher_issuance?id=${id}&phone=${info.value.mobile}`
		})
	}
	
	const toggleConsu = () =>{
		uni.navigateTo({
			url: `/pages/user/consumption_record?id=${id}`
		})
	}
</script>

<style lang="scss" scoped>
	.page{
		background-color: #F3F3F3 !important;
	}
	.relative {
		position: relative;
	}

	.box {
		border-radius: 12px;
		overflow: hidden;
		padding: 20rpx;
	}

	.tag {
		position: absolute;
		top: 30rpx;
		right: -40rpx;
		font-size: 28rpx;
		transform: rotate(40deg);
		background-color: rgba(253, 128, 8, 0.8);
		color: #fff;
		width: 240rpx;
		text-align: center;
	}

	.image {
		width: 100%;
		margin-top: 20rpx;
	}

	.card {
		background-color: #fff;
		margin-top: 20rpx;
		padding: 20rpx;
		border-radius: 12rpx;
		font-size: 28rpx;

		view {

			padding: 20rpx 0;

			label {
				font-size: 32rpx;
				font-weight: 500;
				min-width: 320rpx;
				margin-right: 20rpx;
			}
		}
	}

	.border-bottom {
		border-bottom: 1px solid #f1f1f1;
	}

	.tabbar {
		position: fixed;
		left: 0;
		right: 0;
		bottom: 0;
	}

	.btn {
		height: 60rpx;
		border-radius: 20rpx;
	}

	.popup {
		height: 50vh;
		padding: 40rpx;

		.title {
			font-size: 15px;
			text-align: center;
			margin-bottom: 60rpx;
			font-weight: 500;

		}

		.margin-top-xxl {
			margin-top: 60rpx;
		}
	}

	.tabbar {
		padding: 0 20rpx;
		padding-bottom: 40rpx;
	}

	.footer {
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		padding: 20rpx;
		padding-bottom: calc(20rpx + var(--status-bar-height));
		background-color: #fff;
		display: flex;
		align-items: center;
		gap: 20rpx;
		justify-content: space-between;
		.fbtn{
			flex: 1;
			margin: 0 7rpx;
			height: 81rpx;
			border-radius: 50rpx;
			border: 1rpx solid #4D81EF;
			display: flex;
			align-items: center;
			justify-content: center;
			font-weight: 400;
			font-size: 28rpx;
			color: #4D81EF;
		}
		.cha{
			background-color: rgba(77, 129, 239, 1);
			color: #fff;
			border: none;
		}
	}

	// 新列表样式开始
	.nlist{
		.nitem{
			margin: 20rpx;
			background-color: #fff;
			// padding: 30rpx 0 30rpx 30rpx;
			display: flex;
			flex-direction: column;
			border-radius: 20rpx;
			.oneitem{
				display: flex;
				flex-direction: row;
				align-items: center;
				margin: 20rpx 0rpx 0rpx 20rpx;
				position: relative;
				.tous{
					width: 44rpx;
					height: 44rpx;
					border-radius: 50%;
				}
				.onename{
					font-weight: bold;
					font-size: 32rpx;
					color: #1A1A1A;
					display: inline-block;
					margin-left: 10rpx;
				}
				.zixing{
					margin-left: auto;
					background: #EDF2FF;
					border-radius: 5rpx 0rpx 0rpx 5rpx;
					padding: 4rpx 20rpx;
					font-weight: 400;
					font-size: 20rpx;
					color: #6194FF;
				}
			}
			.twoitem{
				display: flex;
				flex-direction: column;
				padding: 30rpx;
				background-color: rgba(244, 246, 249, 0.8);
				border-radius: 20rpx;
				margin: 30rpx;
				.hengone{
					display: flex;
					flex-direction: column;
					margin-bottom: 20rpx;
				}
				.hengone:last-child{
					margin-bottom: 0;
				}
				.heng{
					display: flex;
					flex-direction: row;
					align-items: center;
					.hitem{
						display: flex;
						flex-direction: row;
						align-items: center;
						flex: 1;
						.hleft{
							font-weight: 400;
							font-size: 28rpx;
							color: #666666;
							width: 150rpx;
							display: inline-block;
						}
						.hright{
							font-weight: 500;
							font-size: 28rpx;
							color: #1A1A1A;
							max-width: 73%;
							display: inline-block;
						}
					}
					.ban{
						width: 50%;
					}
					.ban:nth-child(even){
						margin-left: auto;
					}
				}
			}
		}
	}
	// 新列表样式结束
	.txt{
		overflow: hidden;  //超出隐藏
		white-space: nowrap; //不折行
		text-overflow: ellipsis; //溢出显示省略号
	}
</style>